package _7线程的控制;


class YieldThread extends Thread
{
	@Override
	public void run() 
	{
		for(int i=0;i<1000;i++)
		{
			// 让他有1/2的礼让出cpu
			if(i%2==0)
			{
				Thread.yield();
			}
			System.out.println(Thread.currentThread().getName()+i);
		}
	}
}

class NormalThread extends Thread {
	@Override
	public void run() {
		for (int i = 0; i < 1000; i++) {
			System.out.println(Thread.currentThread().getName() + i);
		}
	}
}

public class YieldThreadDemo {

	public static void main(String[] args) {
		
		YieldThread t1 = new YieldThread();
		t1.setName("yield1");
		NormalThread t2 = new NormalThread();
		t2.setName("normal");
		
		t1.start();
		t2.start();
	}
}
